package com.example.administrator.college02.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;

/**
 * Created by Administrator on 2016/7/11.
 */
public class MyPageAdapter extends PagerAdapter{

        private ArrayList<Fragment> arrayList;
        private FragmentManager manager;

        public MyPageAdapter(FragmentManager manager, ArrayList<Fragment> arrayList) {
            this.arrayList = arrayList;
            this.manager = manager;
        }

        @Override
        public int getCount() {
            return arrayList.size();//视图容量
        }

        @Override
        public boolean isViewFromObject(View view, Object object) {
            return view==object;
        }

        @Override
        public Object instantiateItem(ViewGroup container, int position) {

            container.addView(arrayList.get(position).getView());//每个视图位置添加View
            return arrayList.get(position);
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            container.removeView(arrayList.get(position).getView());//移除当前视图
        }
}